/*
 * Created on 2005-6-24
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.linkage.lcims.base.dao.customer.impl;

import java.util.List;
import java.util.Map;

import com.linkage.lcims.base.dao.HibernateBaseDAOImpl;
import com.linkage.lcims.base.dao.customer.interfaces.CustomerDAO;
import com.linkage.lcims.base.po.customer.MCustomer;
import com.linkage.util.exception.DAOException;
import com.linkage.util.service.Hash163;

/**
 * @author Administrator
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
@SuppressWarnings("unchecked")
public class CustomerDAOImpl extends HibernateBaseDAOImpl implements
		CustomerDAO {

	private static final String PO_CLASS = "com.linkage.lcims.base.po.customer.MCustomer";

	public MCustomer getCustomer(String customerName) throws Exception {
		try {
			return (MCustomer) this.getByID(Hash163.CUSHash(customerName),
					customerName);
		} catch (Exception e) {
			throw new DAOException(e);
		}

	}

	public void saveCustomer(MCustomer customer) throws Exception {
		String customerName = customer.getCustomername();
		try {
			this.save(Hash163.CUSHash(customerName), customer);
		} catch (Exception e) {
			throw new DAOException(e);
		}

	}

	public void updateCustomer(MCustomer customer) throws Exception {
		String customerName = customer.getCustomername();
		try {
//			this.update(Hash163.CUSHash(customerName), customer);
			this.merge(Hash163.CUSHash(customerName), customer);//zhaigx
		} catch (Exception e) {
			throw new DAOException(e);
		}
	}

	public void deleteCustomer(MCustomer customer) throws Exception {
		String customerName = customer.getCustomername();
		try {
			this.delete(Hash163.CUSHash(customerName), customerName);
		} catch (Exception e) {
			throw new DAOException(e);
		}
	}

	public List getCustomers(String hql, String param, String value)
			throws Exception {
		return this.query(hql, param, value);
	}

	public void updateFields(String customerName, Map fieldValues)
			throws DAOException {
		try {
			this.updateEntityField(Hash163.CUSHash(customerName), PO_CLASS,
					customerName, fieldValues);
		} catch (Exception e) {
			throw new DAOException(e);
		}
	}
}
